package com.example.wisecarparking.controller;

import com.example.wisecarparking.dao.RecordMapper;
import com.example.wisecarparking.dao.RecordRepo;
import com.example.wisecarparking.domain.Record;
import com.example.wisecarparking.service.RecordService;
import org.apache.coyote.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/record")
public class RecordController {

    @Autowired
    RecordService recordService;

    @Autowired
    RecordRepo recordRepo;

    //增加
    @PostMapping("/add")
    @ResponseBody
    public String addRecord(@RequestBody Record record ){
        record.setId(UUID.randomUUID().toString());
        //记录生成时间戳
        record.setInTimestamp(String.valueOf(System.currentTimeMillis()));
        //数据校验
        recordService.insertRecord(record);
        return record.getCarCode();
    }
    //删除
    @DeleteMapping
    @ResponseBody
    public String deleteById(@RequestParam("id") String id){
        recordRepo.deleteById(id);
        return "删除成功。";
    }
    //查询
    @GetMapping("/list")
    @ResponseBody
    public List<Record> queryAll(@RequestBody Record record ){
       return recordService.queryList(record);
    }

    @GetMapping("/rep/list")
    @ResponseBody
    public List<Record> queryAllByRep(@RequestBody Record record){
        return recordRepo.findAll();
    }
    //修改
}
